/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_HOST_HAL_H
#define SLE_HOST_HAL_H

#ifndef SLE_LOG_TAG
#define SLE_LOG_TAG "[SleHal]"
#endif

#include "sle_host_hdi.h"
#include "sle_hal_errcode.h"
#include "sle_device_config.h"
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 *  @brief  enable sle result callback
 * 
 *  @param  [in] errCode - enable result
 *  @return None
 */
typedef void (*SleHalEnableSleCallback)(SleHalErrorCode errCode);

/**
 *  @brief  disable sle result callback
 * 
 *  @param  [in] errCode - disable result
 *  @return None
 */
typedef void (*SleHalDisableSleCallback)(SleHalErrorCode errCode);

typedef struct {
    SleHalEnableSleCallback OnHostHalEnableSleCb;
    SleHalDisableSleCallback OnHosthalDisableSleCb;
} SleHostHalCallbacks;

/**
 *  @brief  initialize the host hal
 * 
 *  @param  None
 *  @return SleHalErrorCode
 */
SleHalErrorCode InitSleHostHal(void);

/**
 *  @brief  deinitialize the host hal
 * 
 *  @param  None
 *  @return SleHalErrorCode
 */
SleHalErrorCode DeinitSleHostHal(void);

/**
 *  @brief  enable the host hal
 * 
 *  @param  None
 *  @return SleHalErrorCode
 */
SleHalErrorCode SleHostHalEnableSle(void);

/**
 *  @brief  disable the host hal
 * 
 *  @param  None
 *  @return SleHalErrorCode
 */
SleHalErrorCode SleHostHalDisableSle(void);

/**
 *  @brief  set the host address
 * 
 *  @param  [in] hostAddr - host address
 *  @return SleHalErrorCode
 * 
 *  @note address should not be NULL and be freed by user.
 */
SleHalErrorCode SleHostHalSetHostAddress(const SleDeviceAddress *hostAddr);

/**
 *  @brief  get the host address
 * 
 *  @param  [inout] hostAddr - host address ([in] addrType, [out] addr)
 *  @return SleHalErrorCode
 */
SleHalErrorCode SleHostHalGetHostAddress(SleDeviceAddress *hostAddr);

/**
 *  @brief  set the host name
 * 
 *  @param  [in] name - host name
 *  @param  [in] len - host name length
 *  @return SleHalErrorCode
 */
SleHalErrorCode SleHostHalSetHostName(const uint8_t *name, const uint8_t len);

/**
 *  @brief  get the host name
 * 
 *  @param  [out] name - host name
 *  @param  [out] len - host name length
 *  @return SleHalErrorCode
 */
SleHalErrorCode SleHostHalGetHostName(uint8_t *name, uint8_t *len);

/**
 *  @brief  register the host callback
 * 
 *  @param  [in] halHostCallback - host callback
 *  @return SleHalErrorCode
 * 
 *  @note halHostCallback should not be NULL and be freed by user.
 */
SleHalErrorCode SleHostHalRegisterCallback(const SleHostHalCallbacks *halHostCallback);

/**
 *  @brief  read data in the na partition
 * 
 *  @param  [in] key -  key id of the nv item to be read
 *  @param  [in] kvalue_max_length -  maximum length allowed for storing data
 *  @param  [out] kvalue_length -  actual length of data read
 *  @param  [out] kvalue -  pointer to the buffer that stores and reads data
 *  @return SleErrorCode - operation result
 */
SleHalErrorCode SleHostHalUapiNvRead(uint16_t key, uint16_t kvalue_max_length, uint16_t *kvalue_length, uint8_t *kvalue);

/**
 *  @brief  write nv data item
 * 
 *  @param  [in] key -  key id of the nv item to be write
 *  @param  [in] kvalue -  pointer to the value of the NV item to be written
 *  @param  [in] kvalue_length -  The length of data written (in bytes)
 *  @return SleErrorCode - operation result
 */
SleHalErrorCode SleHostHalUapiNvWrite(uint16_t key, uint8_t *kvalue, uint16_t kvalue_length);

#ifdef __cplusplus
}
#endif

#endif // SLE_HOST_HAL_H